package generator;

import java.util.Iterator;
import java.util.List;

import org.dom4j.*;

/**
 * experimental wrapper class for a OpenOffice Writer document in Dom4j XML
 * 
 * OpenOffice.org Version 3+
 * 
 * @author jeznicholson
 *
 */
public class Dom4jOpenOfficeDoc {

	public Dom4jOpenOfficeDoc(Document dom4jOODocument) {
		document = dom4jOODocument;
	}

	public Dom4jOpenOfficeDoc(OpenOfficeDoc ooDocument) throws DocumentException {
		document = ooDocument.getDocument();
	}

	public Node getFontDeclrs() {
		Node node = document.selectSingleNode( "//office:font-face-decls");
		return node;
	}
	
	public void listStyles() {
		List<Node> styles = getFontDeclrs().selectNodes("style:font-face");
		Iterator<Node> it = styles.iterator();
		while (it.hasNext()) {
			Node node = (Node)it.next();
			System.out.println("style "+node.valueOf("@style:name")+" font="+node.valueOf("@svg:font-family"));
		}
	}

	public Node getBody() {
		Node node = document.selectSingleNode( "//office:body");
		return node;
	}

	public List getHeadings() {
		List nodes = document.selectNodes("//text:h");
		return nodes;
	}
	
	public List getHeadedBlock() {
		List nodes = document.selectNodes("/following::/office:document-content/office:body/text:h[1]");
		return nodes;
	}
	
	public Node getText() {
		Node node = document.selectSingleNode("//office:text");
		return node;
	}

	private Document document;
}
